﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Drawing;
using ITAP.ShprossesBuilder.Modelling;
using System.Windows.Forms;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Manipulation
{
    public class CommandEditorSelectModelCell : IModelComponentCommand
    {
        private MouseManagerEvent mouseEvent;

        public MouseManagerEvent MouseEvent
        {
            get { return mouseEvent; }
            set { mouseEvent = value; }
        }

        private bool executeImmediately = false;

        public bool ExecuteImmediately
        {
            get { return executeImmediately; }
            set { executeImmediately = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
        }
        private Point mouseDownPoint;
        private ModelControl modelControl;

        public CommandEditorSelectModelCell(ModelControl modelControl, string name)
        {
            this.name = name;
            this.modelControl = modelControl;
        }

        #region IModelControlCommand Members

        public ModelControl ModelControl
        {
            get
            {
                return modelControl;
            }
            set
            {
                modelControl = value;
            }
        }

        public System.Drawing.Point MouseDownPoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        public System.Drawing.Point MouseUpPoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        public System.Drawing.Point MouseMovePoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        #endregion

        #region ICommand Members

        public void StartExecute()
        {
            ModelPoint modelPoint = modelControl.ScreenToModel(MouseDownPoint);
            modelControl.ModelContainer.SelectActiveModelCellByPoint(modelPoint);
        }

        public void Execute()
        {
            //ModelPoint modelPoint = modelControl.ScreenToModel(MouseMovePoint);
            //modelControl.ModelContainer.SelectActiveModelCellByPoint(modelPoint);
        }

        public void EndExecute()
        {
            ModelPoint modelPoint = modelControl.ScreenToModel(MouseUpPoint);
            modelControl.ModelContainer.SelectActiveModelCellByPoint(modelPoint);
        }

        public bool CanUndo
        {
            get { return false; }
        }

        public bool Undo(ModelControl modelControl)
        {
            throw new NotImplementedException();
        }

        public bool Redo(ModelControl modelControl)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            CommandEditorSelectModelCell clone = new CommandEditorSelectModelCell(modelControl, name);
            clone.MouseEvent = this.MouseEvent;
            clone.ExecuteImmediately = this.ExecuteImmediately;
            clone.MouseDownPoint = this.MouseDownPoint;
            clone.MouseMovePoint = this.MouseMovePoint;
            clone.MouseUpPoint = this.MouseUpPoint;
            if(this.ComponentsForProcessing != null)
                clone.ComponentsForProcessing = new List<ITAP.ShprossesBuilder.Modelling.Components.IComponent>(this.ComponentsForProcessing);
            return clone;
        }

        #endregion

        #region IModelComponentCommand Members

        public List<ITAP.ShprossesBuilder.Modelling.Components.IComponent> ComponentsForProcessing
        {
            get
            {
                return null;
            }
            set
            {
            }
        }

        #endregion

        #region ICommand Members


        public bool IsNeedModelUpdate
        {
            get { return false; }
        }

        #endregion

        #region ICommand Members


        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        #endregion

        #region ICommand Members


        // TODO: Не уверен насчёт того, false тут должно быть или true.
        public bool IsNeedVisitorsUpdate
        {
            get { return false; }
        }

        #endregion
    }
}
